import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:o2oa_all_platform/common/extension/string_extension.dart';

import '../../../../common/models/clouddisk/zone_info.dart';
import '../../../../common/routers/index.dart';
import '../../../../common/style/theme.dart';
import 'index.dart';

class EnterpriseZonePermissionPage
    extends GetView<EnterpriseZonePermissionController> {
  const EnterpriseZonePermissionPage({Key? key}) : super(key: key);

  static Future<dynamic> open(CloudDiskZoneInfo zone) async {
    return await Get.toNamed(O2OARoutes.appCloudDiskV3EnterpriseZonePermission,
        arguments: zone);
  }

  // 主视图
  Widget _buildView() {
    return Obx(() => ListView.separated(
          separatorBuilder: (context, index) => const Divider(height: 1),
          itemCount: controller.state.zonePermissionList.length,
          itemBuilder: (context, index) {
            final item = controller.state.zonePermissionList[index];
            return Container(
                color: Theme.of(context).colorScheme.surface,
                child: ListTile(
                    onTap: () => controller.clickZonePermission(item),
                    title: Text((item.name ?? '').o2NameCut(),
                        style: Theme.of(context).textTheme.bodyLarge),
                    trailing: Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        mainAxisSize: MainAxisSize.min,
                        children: [
                          Text(controller.roleName(item.role ?? ''),
                              style: Theme.of(context).textTheme.bodySmall),
                          const Icon(Icons.keyboard_arrow_right)
                        ])));
          },
        ));
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<EnterpriseZonePermissionController>(
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            title: Obx(() => Text(controller.state.title)),
            actions: [
              TextButton(
                  onPressed: () => controller.clickAddPermission(),
                  child: Text('cloud_disk_v3_zone_permission_add'.tr,
                      style: AppTheme.whitePrimaryTextStyle))
            ],
          ),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
